# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Łukasz Jendrysik <scadu@yandex.com>
# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer:
pkgname=sudo-ldap
pkgver=1.9.14
if [ "${pkgver%_*}" != "$pkgver" ]; then
	_realver=${pkgver%_*}${pkgver#*_}
else
	_realver=$pkgver
fi
pkgrel=1
pkgdesc="Give certain users the ability to run some commands as root (ldap+pam support)"
url="https://www.sudo.ws/sudo/"
arch="all"
license="custom ISC"
makedepends="
	linux-pam-dev
	openldap-dev
	zlib-dev
	"
source="https://www.sudo.ws/dist/sudo-$_realver.tar.gz"
options="suid"
builddir="$srcdir/sudo-$_realver"

provides="sudo-virt"
provider_priority=2
replaces="sudo"

build() {
	CFLAGS="$CFLAGS -flto=auto" \
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--libexecdir=/usr/lib \
		--mandir=/usr/share/man \
		--disable-nls \
		--enable-pie \
		--with-env-editor \
		--with-mdoc \
		--with-pam \
		--with-ldap \
		--with-ldap-conf-file=/etc/ldap.conf.sudo \
		--with-nsswitch=no \
		--without-skey \
		--with-sendmail=/usr/sbin/sendmail \
		--with-passprompt="[sudo] password for %p: "

	make
}

check() {
	make check
}

package() {
	# the sudo's mkinstalldir script miscreates the leading
	# path components with bad permissions. fix this.
	install -d -m0755 "$pkgdir"/var "$pkgdir"/var/db
	make -j1 DESTDIR="$pkgdir" install
	rm -rf "$pkgdir"/var/run

	# just docs
	# use these from sudo-doc
	# shellcheck disable=2115
	rm -r "$pkgdir"/usr/share

	# just sudo_plugin.h, use sudo-dev
	# shellcheck disable=2115
	rm -r "$pkgdir"/usr/include

	# Exactly the same as /etc/sudoers
	rm "$pkgdir"/etc/sudoers.dist
}

sha512sums="
33d3bc3d66b1c5412b7d579b703d44f246386d2915c1c63be851869569c7bc627211a8897d0bc718d6ebb2bdd938b093c0901f0b7912c8475f8e6fcbbc559a99  sudo-1.9.14.tar.gz
"
